import 'package:flutter/material.dart';
import 'package:tiktokadult/tools_base/widget/keep_alive_widget.dart';

import 'cartoon_sectionlist_sub_page.dart';

//专题更多
class CartoonSectionListPage extends StatefulWidget {
  final String? sectionID;
  final String? tagName;
  final int pageType; //0是动漫  1是漫画
  final String? kind;

  const CartoonSectionListPage({
    super.key,
    this.sectionID,
    this.tagName,
    this.pageType = 0,
    this.kind,
  });

  @override
  State<CartoonSectionListPage> createState() => _CartoonSectionListPageState();
}

class _CartoonSectionListPageState extends State<CartoonSectionListPage> with TickerProviderStateMixin {
  List<String> tabs = ['最多收藏', '最新上架', '最多观看'];
  late TabController tabCtr = TabController(length: tabs.length, vsync: this);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text(widget.tagName ?? '')),
        body: Column(
          children: [
            _buildTabs(),
            Expanded(
              child: TabBarView(
                controller: tabCtr,
                children: [
                  CartoonSectionSubPage(
                    sortType: 3,
                    sectionID: widget.sectionID,
                  ).keepAlive,
                  CartoonSectionSubPage(
                    sortType: 1,
                    sectionID: widget.sectionID,
                  ).keepAlive,
                  CartoonSectionSubPage(
                    sortType: 2,
                    sectionID: widget.sectionID,
                  ).keepAlive,
                ],
              ),
            )
          ],
        ));
  }

  _buildTabs() {
    return Container(
      padding: EdgeInsets.only(bottom: 3),
      alignment: Alignment.center,
      child: TabBar(
        tabAlignment: TabAlignment.center,
        controller: tabCtr,
        tabs: List.generate(
          tabs.length,
          (index) => Container(
            padding: EdgeInsets.symmetric(horizontal: 16),
            child: Text(tabs[index]),
            decoration: BoxDecoration(
              border: index != 2
                  ? Border(
                      right: BorderSide(width: .5, color: Colors.white.withOpacity(.1)),
                    )
                  : null,
            ),
          ),
        ),
        labelColor: Colors.white.withOpacity(.9),
        labelPadding: EdgeInsets.zero,
        labelStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
        unselectedLabelColor: Colors.white.withOpacity(0.5),
        unselectedLabelStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400),
        indicator: BoxDecoration(),
      ),
    );
  }
}
